/**   
* @Title: DaiZhongYwVontroller.java 
* @Package com.zjdiepu.www.manage.api.zpp.controller 
* 
* @author zhangpp
* @date 2017年5月27日 上午10:05:37 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.annotation.Add;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.commpent.RedisObjectClient;
import com.zjdiepu.www.dao.dz.DzMortgageSubMapper;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.dz.IDzMortgageService;
import com.zjdiepu.www.ibiz.dz.IDzMortgageSubService;
import com.zjdiepu.www.ibiz.system.IBaseSalersmanService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.zpp.CaiWuXiangGuanService;
import com.zjdiepu.www.ibiz.zpp.DaiZhongYwService;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.ibiz.zpp.SystemService;
import com.zjdiepu.www.model.base.dto.SimpleDataDictionary;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.dz.dto.DzLoanExit;
import com.zjdiepu.www.model.dz.dto.DzMortgage;
import com.zjdiepu.www.model.dz.dto.DzMortgageSub;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.zpp.dzyw.vo.BusinessVo;
import com.zjdiepu.www.model.zpp.pub.ext.ParamsExt;
import com.zjdiepu.www.model.zpp.pub.ext.UpdateYwExt;
import com.zjdiepu.www.model.zpp.pub.vo.ParamsVo;

/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：DaiZhongYwVontroller   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月27日 上午10:05:37   
 * 修改人：zhangpp
 * 修改时间：2017年5月27日 上午10:05:37   
 * 修改备注：   
 * @version V1.0     
 */
@RestController
@RequestMapping(value= "DaiZhongYwController", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class DaiZhongYwController extends BaseController
{
	@Resource
	private DaiZhongYwService daiZhongYwService;
	
	@Resource
	private ICachedDictionaryService iCachedDictionaryService;
	
	@Resource
	private IDzMortgageService iDzMortgageService;
	
	@Resource
	private IDzMortgageSubService iDzMortgageSubService;
	
	@Resource
	private CaiWuXiangGuanService caiWuXiangGuanService;
	
	@Resource
	private IYwBusinessService iywBusinessService;
	
	@Resource
	private RedisObjectClient redisObjectClient;
	
	@Resource
    private ICachedDictionaryService cachedDictionaryService;
	
	@Resource
	private IBaseSalersmanService iBaseSalersmanService;
	
	@Resource
	private PublicService publicService;
	
	@Resource
	private SystemService systemService;
	
	@Resource
	private DzMortgageSubMapper dzMortgageSubMapper;
	
	/**
	* 贷中业务 抵押确认
	* @author zhangpp
	* @Title: daizhongYwDiYaQueRen 
	* 
	* @param @param paramsExt
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="daizhongYwDiYaQueRen",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> daizhongYwDiYaQueRen(DzMortgage dzMortgage)
	{
		Map<String, Object> maps = success();
		AbstractSysUser currentUser = getCurrentUser();
    	daiZhongYwService.diepuDiYaQueRen(currentUser, dzMortgage);
		return maps;
	}
	
	/**
	* 贷中业务 抵押确认
	* @author zhangpp
	* @Title: daiZhongYwDiYaQueRrnSubSave 
	* 
	* @param @param dzMortgageSub
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@ApiOperation(value = "贷中业务 抵押确认", response = Boolean.class, httpMethod="POST", tags={"贷中业务 抵押确认"})
    @RequestMapping(value = "daiZhongYwDiYaQueRrnSubSave", method = RequestMethod.POST)
    public ApiResponse daiZhongYwDiYaQueRrnSubSave(@Validated(Add.class) @ModelAttribute DzMortgageSub dzMortgageSub,int index,int type) 
	{
		//查询此数据有没有
		AbstractSysUser currentUser = getCurrentUser();
		DzMortgageSub mortgageSub = new DzMortgageSub();
		mortgageSub.setBusiId(dzMortgageSub.getBusiId());
		mortgageSub.setDpStatus(1);
		DzMortgageSub dzsub = iDzMortgageSubService.selectRefined(mortgageSub);
		if(null == dzsub)
		{
			dzMortgageSub.initInsertData(currentUser.getId(), currentUser.getName());
	    	dzMortgageSubMapper.insert(dzMortgageSub);
	    	return ApiResponse.success(true);
		}
		
		if(index > 0 && index <= 17)
		{
			if(type == 1)
			{
				if(null == dzsub || ("").equals(dzsub))
				{
					dzMortgageSub.initInsertData(currentUser.getId(), currentUser.getName());
			    	dzMortgageSubMapper.insert(dzMortgageSub);
			    	return ApiResponse.success(true);
				}
				//修改数据
				dzMortgageSub.initUpdateData(currentUser.getId(), currentUser.getName());
				dzMortgageSubMapper.updateByPrimaryKeySelective(dzMortgageSub);
				return ApiResponse.success(true);
			}
			
			if(type == 2)
			{
				if(null == dzsub || ("").equals(dzsub))
				{
					dzMortgageSub.initInsertData(currentUser.getId(), currentUser.getName());
			    	dzMortgageSubMapper.insert(dzMortgageSub);
			    	return ApiResponse.success(true);
				}
				
				if(index == 1)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateDjzsyj(null);
					dzsub.setOperatorDjzsyj(null);
					dzsub.setNameOperatorDjzsyj(null);
					dzsub.setTimeDjzsyj(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 2)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateFpyj(null);
					dzsub.setOperatorFpyj(null);
					dzsub.setNameOperatorFpyj(null);
					dzsub.setTimeFpyj(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 3)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateZzzyj(null);
					dzsub.setOperatorZzzyj(null);
					dzsub.setNameOperatorZzzyj(null);
					dzsub.setTimeZzzyj(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 4)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateSybxyj(null);
					dzsub.setOperatorSybxyj(null);
					dzsub.setNameOperatorSybxyj(null);
					dzsub.setTimeSybxyj(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 5)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateJqxbdyj(null);
					dzsub.setOperatorJqxbdyj(null);
					dzsub.setNameOperatorJqxbdyj(null);
					dzsub.setTimeJqxbdyj(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 6)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateXszfyj(null);
					dzsub.setOperatorXszfyj(null);
					dzsub.setNameOperatorXszfyj(null);
					dzsub.setTimeXszfyj(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 7)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateGzclsyhgz(null);
					dzsub.setOperatorGzclsyhgz(null);
					dzsub.setNameOperatorGzclsyhgz(null);
					dzsub.setTimeGzclsyhgz(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 8)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateGzclyhgzfh(null);
					dzsub.setOperatorGzclyhgzfh(null);
					dzsub.setNameOperatorGzclyhgzfh(null);
					dzsub.setTimeGzclyhgzfh(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 9)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateGzclsgzc(null);
					dzsub.setOperatorGzclsgzc(null);
					dzsub.setNameOperatorGzclsgzc(null);
					dzsub.setTimeGzclsgzc(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 10)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateGzcgzhtfh(null);
					dzsub.setOperatorGzcgzhtfh(null);
					dzsub.setNameOperatorGzcgzhtfh(null);
					dzsub.setTimeGzcgzhtfh(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 11)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateGzjdyclfhgs(null);
					dzsub.setOperatorGzjdyclfhgs(null);
					dzsub.setNameOperatorGzjdyclfhgs(null);
					dzsub.setTimeGzjdyclfhgs(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 12)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateSjgz(null);
					dzsub.setOperatorSjgz(null);
					dzsub.setNameOperatorSjgz(null);
					dzsub.setTimeSjgz(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 13)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateDyclsyhgz(null);
					dzsub.setOperatorDyclsyhgz(null);
					dzsub.setNameOperatorDyclsyhgz(null);
					dzsub.setTimeDyclsyhgz(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 14)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateDyclyhgzfh(null);
					dzsub.setOperatorDyclyhgzfh(null);
					dzsub.setNameOperatorDyclyhgzfh(null);
					dzsub.setTimeDyclyhgzfh(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 15)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateDyclsdyry(null);
					dzsub.setOperatorDyclsdyry(null);
					dzsub.setNameOperatorDyclsdyry(null);
					dzsub.setTimeDyclsdyry(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 16)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateDywcdjzsfh(null);
					dzsub.setOperatorDywcdjzsfh(null);
					dzsub.setNameOperatorDywcdjzsfh(null);
					dzsub.setTimeDywcdjzsfh(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
				else if(index == 17)
				{
					dzsub.initUpdateData(currentUser.getId(), currentUser.getName());
					dzsub.setDateDywcqzyjyh(null);
					dzsub.setOperatorDywcqzyjyh(null);
					dzsub.setNameOperatorDywcqzyjyh(null);
					dzsub.setTimeDywcqzyjyh(null);
					dzMortgageSubMapper.updateByPrimaryKey(dzsub);
				}
			}
		}
		return ApiResponse.success(true);
    }
	
	
	/**
	* 贷中业务 抵押确认
	* @author zhangpp
	* @Title: daiZhongYwDiYaQueRrnSave 
	* 
	* @param @param dzMortgage
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@ApiOperation(value = "贷中业务 抵押确认", response = Boolean.class, httpMethod="POST", tags={"贷中业务 抵押确认"})
    @RequestMapping(value = "daiZhongYwDiYaQueRrnSave", method = RequestMethod.POST)
    public ApiResponse daiZhongYwDiYaQueRrnSave(@Validated(Add.class) @ModelAttribute DzMortgage dzMortgage) {
    	AbstractSysUser currentUser = getCurrentUser();
    	daiZhongYwService.diepuDaiZhongYwDiYaQueRrnSave(dzMortgage, currentUser);
        return ApiResponse.success(true);
    }
	
	/**
	* 贷中业务 抵押确认
	* @author zhangpp
	* @Title: getDataDictionaryList 
	* 
	* @param @param paramsExt
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="daiZhongYwDiYaQueRrnList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> daiZhongYwDiYaQueRrnList(ParamsExt paramsExt)
	{
		Map<String, Object> maps = success();
		
		//车辆抵押状态
		Map<String, String> MortgageStatus = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.MORTGAGESTATUS,"请选择...");
		maps.put("MortgageStatus", MortgageStatus);
		
		//查询 dz_mortgage
		DzMortgage dzMortgage = new DzMortgage();
		dzMortgage.setBusiId(paramsExt.getBusiId());
		dzMortgage = iDzMortgageService.selectRefined(dzMortgage);
		if(dzMortgage!=null){
			if(null != dzMortgage.getStatusMortgage())
			{
					dzMortgage.setStatusMortgageDisplay(iCachedDictionaryService.getName(dzMortgage.getStatusMortgage().toString(), DataDicType.MORTGAGESTATUS));
			}
			maps.put("dzMortgage", dzMortgage);
			
		}else{
			maps.put("dzMortgage", null);
		}
		
		//查询 dz_mortgage_sub
		DzMortgageSub dzMortgageSub = new DzMortgageSub();
		dzMortgageSub.setBusiId(paramsExt.getBusiId());
		dzMortgageSub = iDzMortgageSubService.selectRefined(dzMortgageSub);
		maps.put("dzMortgageSub", dzMortgageSub);
		return maps;
	}
	
	/**
	* 贷中业务 退贷表 进行修改状态 
	* @author zhangpp
	* @Title: daiZhongYwTuiDaiBiao 
	* 
	* @param @param dzLoanExit
	* @param @param ywBusiness
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="daiZhongYwTuiDaiBiao",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse daiZhongYwTuiDaiBiao(@ApiIgnore DzLoanExit dzLoanExit,YwBusiness ywBusiness)
	{
		AbstractSysUser currentUser = getCurrentUser();
		daiZhongYwService.diepuDaiZhongYwTuiDaiBiao(dzLoanExit, ywBusiness, currentUser);
		return ApiResponse.success(true);
	}
	
	/**
	* 贷中业务  退贷表
	* @author zhangpp
	* @Title: getDataDictionaryList 
	* 
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getDataDictionaryList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getDataDictionaryList(ParamsExt paramsExt)
	{
		Map<String, Object> maps = success();
		
		//退贷原因
		Map<String, String> LoanExitReason_Result = iCachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOANEXIT_REASON,"请选择...");
		maps.put("LoanExitReason_Result", LoanExitReason_Result);
		
		//退款时间
		ParamsVo result = daiZhongYwService.gettimeArrive(paramsExt);
		maps.put("result", result);
		return maps;
	}
	
	/**
	* 贷中业务 贷中信息登记  银行放款
	* @author zhangpp
	* @Title: bankDaiKuanDataOp 
	* 
	* @param @param paramsExt
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="bankDaiKuanDataOp",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse bankDaiKuanDataOp(@ApiIgnore ParamsExt paramsExt)
	{
		AbstractSysUser currentUser = getCurrentUser();
		daiZhongYwService.diepuBankDaiKuanDataOp(paramsExt,currentUser);
		return ApiResponse.success(true);
	}
	
	/**
	* 贷中业务 贷中信息登记  银行贷款 
	* @author zhangpp
	* @Title: getBankFangKuanList 
	* 
	* @param @param paramsExt
	* @param @return
	* @param @throws Exception    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value="getBankFangKuanList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getBankFangKuanList(@ApiIgnore ParamsExt paramsExt) throws Exception
	{
		Map<String, Object> maps = success();
		
		String whereSql = "";
		
		if(null != paramsExt && !("").equals(paramsExt))
		{
			String customerName = paramsExt.getCustomerName();
			String salesmanName = paramsExt.getSalesmanName();
			
			String dayEnum = paramsExt.getDayEnum();
			
			if(null != dayEnum && !("").equals(dayEnum))
			{
				int stamp = ZhppDateUtil.dateConvertStamp();
				
				if(dayEnum.equals("1"))
				{
					whereSql += " and t.created >= "+stamp + " and t.created < "+(stamp + 86400);
				}
				else if(dayEnum.equals("2"))
				{
					whereSql += " and t.created < "+stamp + " and t.created >= "+(stamp - 86400 * 2);  
				}
				else if(dayEnum.equals("3"))
				{
					whereSql += " and t.created > (unix_timestamp() - 3600 * 24 * 7) ";
				}
			}
			
			String submitTimeStart = paramsExt.getSubmitTimeStart();
			String submitTimeEnd = paramsExt.getSubmitTimeEnd();
			
			if((null != submitTimeStart && !("").equalsIgnoreCase(submitTimeStart)) && (null != submitTimeEnd && !("").equals(submitTimeEnd)))
			{
				int start = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
				int end =  ZhppDateUtil.dateConvertTimeStamp(submitTimeEnd, "yyyy-MM-dd");
				whereSql += " and t.created >= "+start + " and t.created < "+ (end + 86400);
			}
			else
			{
				if(null != submitTimeStart && !("").equals(submitTimeStart))
				{
					int start = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
					whereSql += " and t.created >= "+start;
				}
				else if(null != submitTimeEnd && !("").equals(submitTimeEnd))
				{
					int end =  ZhppDateUtil.dateConvertTimeStamp(submitTimeEnd, "yyyy-MM-dd");
					whereSql += " and t.created < "+(end + 86400);
				}
			}
			
			//主要条件   
			String modularCode = paramsExt.getModularCode();
			//主要条件   
			
			//贷中业务  贷中信息登记  银行放款
			if(null != modularCode && modularCode.equals("M_yhfk"))
			{
				whereSql += " and t.busi_status = 460 ";
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
			}
			
			//贷中业务  退贷
			if(modularCode.equals("M_td"))
			{
				whereSql += " and t.busi_status >= 110 ";
				whereSql += " and t.busi_status < 500  ";
				whereSql += " and t.added_status1 not in(300,500)";
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
			}
			
			//业务受理 按揭日报表登记
			if(modularCode.equals("M_ajrbdj"))
			{
				whereSql += " and t.busi_status >= 50 and t.busi_status <= 500 and t.added_status1 < 100 ";
				
				if(paramsExt.getAddedStatus1() > 0)
				{
					if(paramsExt.getAddedStatus1() == 10)
					{
						whereSql += " and t.added_status1 = "+paramsExt.getAddedStatus1();
					}
					
					if(paramsExt.getAddedStatus1() == 20)
					{
						whereSql += " and t.added_status1 >= "+paramsExt.getAddedStatus1();
					}
				}
				
				
				AbstractSysUser currentUser = getCurrentUser();
				String userId = currentUser.getId();
				String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
				List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
				if(null == mapList || 0 == mapList.size())
				{
					return maps;
				}
				
				if(mapList.size() > 0)
				{
					whereSql += " and ( ";
					Map<String, String> m = mapList.get(0);
					String code_unit = m.get("code_unit").toString();
					whereSql += " u.salersman_code like CONCAT('"+code_unit+"','%') ";
					
					for(int i=1;i<mapList.size();i++)
					{
						m = mapList.get(i);
						code_unit = m.get("code_unit").toString();
						whereSql += " or u.salersman_code like CONCAT('"+code_unit+"','%') ";
					}
					whereSql += " ) ";
				}
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
				
				paramsExt.setWhereSql(whereSql);
				paramsExt.notDeleted();
		        PageVo page = getPage(paramsExt);
		        int records = daiZhongYwService.countByExtBusinessVoList(paramsExt);
		        page.setRecords(records);
		        if (records > 0) 
		        {
		        	paramsExt.setOrderSql(" t.created desc ");
		        	List<BusinessVo> dhywDyVos = daiZhongYwService.getBusinessVoList(paramsExt);
		            redisObjectClient.execute(new RedisCallback<Boolean>() {

						@Override
						public Boolean doInRedis(RedisConnection redisConnection)
								throws DataAccessException {
					            for(int i=0;i<dhywDyVos.size();i++)
					            {
					            	BusinessVo businessVo = dhywDyVos.get(i);
					            	String channelType = businessVo.getChannelType();
					            	SimpleDataDictionary simpleDataDictionary1 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelType, DataDicType.CHANNEL_TYPE.getCode());
					            	businessVo.setChannelType(simpleDataDictionary1 == null ? "" : simpleDataDictionary1.getName());
					            	
					            	String channelStatus = businessVo.getChannelStatus();
					            	SimpleDataDictionary simpleDataDictionary2 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelStatus, DataDicType.CHANNEL_STATUS.getCode());
					            	businessVo.setChannelStatus(simpleDataDictionary2 == null ? "" : simpleDataDictionary2.getName());
					            	
					            	String bankLoan = businessVo.getBankLoan();
					            	SimpleDataDictionary simpleDataDictionary3 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), bankLoan, DataDicType.LOAN_BANK.getCode());
					            	businessVo.setBankLoan(simpleDataDictionary3 == null ? "" : simpleDataDictionary3.getName());
					            
					            	String status_transfer = businessVo.getStatusTransfer();
					            	if(null != status_transfer && status_transfer.equals("20"))
					            	{
					            		businessVo.setStatusTransfer("退回");
					            	}
					            	else
					            	{
					            		businessVo.setStatusTransfer("已提交");
					            	}
					            	dhywDyVos.get(i).setBusiStatusDisplay(iCachedDictionaryService.getName(dhywDyVos.get(i).getBusiStatus().toString(), DataDicType.BUSI_STATUS));
					            }
					            return true;
						}
		            });
		            for(int i=0;i<dhywDyVos.size();i++)
		            {
		            	String dealerId = dhywDyVos.get(i).getDealerId();
		            	sqlXmls = "select t.id,t.dealer_level from dp_base_dealer_info t where t.id = '"+dealerId+"' and t.dp_status = 1 limit 1";
		            	List<Map<String, String>> mpaMaps = publicService.queryWhereSql(sqlXmls);
		            	if(null != mpaMaps && mpaMaps.size() > 0)
		            	{
		            		String dealerLevelDisplay = cachedDictionaryService.getName(mpaMaps.get(0).get("dealer_level"), DataDicType.DEALER_LEVEL);
		            		dhywDyVos.get(i).setDealerLevelDisplay(dealerLevelDisplay);
		            	}
		            }
		            page.setRows(dhywDyVos);
		        } 
		        else 
		        {
		            page.setRows(CollectionInitUtil.emptyList());
		        }
		        maps.put("result", page);
		        return maps;
			}
			
			//业务受理  客户过户登记
			if(modularCode.equals("M_ghdj"))
			{
				whereSql += " and t.busi_status = 200";
				
				//数据范围
				AbstractSysUser currentUser = getCurrentUser();
				String userId = currentUser.getId();
				String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
				List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
				if(null == mapList || 0 == mapList.size())
				{
					return maps;
				}
				
				if(mapList.size() > 0)
				{
					whereSql += " and ( ";
					Map<String, String> m = mapList.get(0);
					String code_unit = m.get("code_unit").toString();
					whereSql += " u.salersman_code like CONCAT('"+code_unit+"','%') ";
					
					for(int i=1;i<mapList.size();i++)
					{
						m = mapList.get(i);
						code_unit = m.get("code_unit").toString();
						whereSql += " or u.salersman_code like CONCAT('"+code_unit+"','%') ";
					}
					whereSql += " ) ";
				}
				//数据范围
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
			}
			
			//财务相关  客户结清
			if(modularCode.equals("M_khjq"))
			{ 
				whereSql += " and sett.auditor is null ";
				paramsExt.setWhereSql(whereSql);
				paramsExt.notDeleted();
		        PageVo page = getPage(paramsExt);
		        int records = caiWuXiangGuanService.getKeHuJieQingCount(paramsExt);
		        page.setRecords(records);
		        if (records > 0) 
		        {
		        	paramsExt.setOrderSql(" t.created desc ");
		        	List<BusinessVo> dhywDyVos = caiWuXiangGuanService.getKeHuJieQingList(paramsExt);
		        	redisObjectClient.execute(new RedisCallback<Boolean>() {

						@Override
						public Boolean doInRedis(RedisConnection redisConnection)
								throws DataAccessException {
							for(int i=0;i<dhywDyVos.size();i++)
							{
								BusinessVo businessVo = dhywDyVos.get(i);
								String channelType = businessVo.getChannelType();
				            	SimpleDataDictionary simpleDataDictionary1 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelType, DataDicType.CHANNEL_TYPE.getCode());
				            	businessVo.setChannelType(simpleDataDictionary1 == null ? "" : simpleDataDictionary1.getName());
				            	
				            	String channelStatus = businessVo.getChannelStatus();
				            	SimpleDataDictionary simpleDataDictionary2 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelStatus, DataDicType.CHANNEL_STATUS.getCode());
				            	businessVo.setChannelStatus(simpleDataDictionary2 == null ? "" : simpleDataDictionary2.getName());
				            	
				            	String bankLoan = businessVo.getBankLoan();
				            	SimpleDataDictionary simpleDataDictionary3 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), bankLoan, DataDicType.LOAN_BANK.getCode());
				            	businessVo.setBankLoan(simpleDataDictionary3 == null ? "" : simpleDataDictionary3.getName());
							}
							return true;
						}
					});
		        	
		        	 for(int i=0;i<dhywDyVos.size();i++)
		             {
		             	String dealerId = dhywDyVos.get(i).getDealerId();
		             	String sqlXmls = "select t.id,t.dealer_level from dp_base_dealer_info t where t.id = '"+dealerId+"' and t.dp_status = 1 limit 1";
		             	List<Map<String, String>> mpaMaps = publicService.queryWhereSql(sqlXmls);
		             	if(null != mpaMaps && mpaMaps.size() > 0)
		             	{
		             		String dealerLevelDisplay = cachedDictionaryService.getName(mpaMaps.get(0).get("dealer_level"), DataDicType.DEALER_LEVEL);
		             		dhywDyVos.get(i).setDealerLevelDisplay(dealerLevelDisplay);
		             	}
		             }
		            page.setRows(dhywDyVos);
		        } 
		        else 
		        {
		            page.setRows(CollectionInitUtil.emptyList());
		        }
		        maps.put("result", page);
		        return maps;
			}
			
			//业务受理 弃贷表
			if(modularCode.equals("M_qdb"))
			{
				//输入条件在查询
				if(StringUtils.isBlank(customerName) && StringUtils.isBlank(salesmanName))
				{
					return maps;
				}
				
				if(null != customerName && !("").equals(customerName))
				{
					whereSql += " and (t.busi_status in (9010,9020,9030,9040,9050,9060) or t.busi_status < 110) ";
				}
				else if(null != salesmanName && !("").equals(salesmanName))
				{
					whereSql += " and (t.busi_status in (9010,9020,9030,9040,9050,9060) or t.busi_status < 110) ";
				}
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
			}
			
			//贷后业务 客户申请退押金
			if(modularCode.equals("M_khsqtyj"))
			{
				whereSql += " and t.busi_status = 9999 ";
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
			}
			
			//贷中业务 抵押确认
			if(modularCode.equals("M_dyqr"))
			{
				whereSql += " and t.busi_status >= 110 and t.busi_status <= 500 ";
				
				String customerNo = paramsExt.getCustomerNo();
				if(StringUtils.isNotBlank(customerNo))
				{
					whereSql += " and t.customer_no like '%"+customerNo+"%' ";
				}
				
				//登录用户银行范围查询
				SysUser sysUser =(SysUser)getCurrentUser();
				String lBank = sysUser.getLoanBank();
				whereSql += systemService.getBankSqlXmls(lBank, "t.bank_loan");
			    //登录用户银行范围查询
			}
		}
		
		paramsExt.setWhereSql(whereSql);
		paramsExt.notDeleted();
        PageVo page = getPage(paramsExt);
        int records = daiZhongYwService.countByExtBusinessVoList(paramsExt);
        page.setRecords(records);
        if (records > 0) 
        {
        	paramsExt.setOrderSql(" t.created desc ");
        	List<BusinessVo> dhywDyVos = daiZhongYwService.getBusinessVoList(paramsExt);
            redisObjectClient.execute(new RedisCallback<Boolean>() {

				@Override
				public Boolean doInRedis(RedisConnection redisConnection)
						throws DataAccessException {
			            for(int i=0;i<dhywDyVos.size();i++)
			            {
			            	BusinessVo businessVo = dhywDyVos.get(i);
			            	String channelType = businessVo.getChannelType();
			            	SimpleDataDictionary simpleDataDictionary1 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelType, DataDicType.CHANNEL_TYPE.getCode());
			            	businessVo.setChannelType(simpleDataDictionary1 == null ? "" : simpleDataDictionary1.getName());
			            	
			            	String channelStatus = businessVo.getChannelStatus();
			            	SimpleDataDictionary simpleDataDictionary2 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelStatus, DataDicType.CHANNEL_STATUS.getCode());
			            	businessVo.setChannelStatus(simpleDataDictionary2 == null ? "" : simpleDataDictionary2.getName());
			            	
			            	String bankLoan = businessVo.getBankLoan();
			            	SimpleDataDictionary simpleDataDictionary3 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), bankLoan, DataDicType.LOAN_BANK.getCode());
			            	businessVo.setBankLoan(simpleDataDictionary3 == null ? "" : simpleDataDictionary3.getName());
			            
			            	String status_transfer = businessVo.getStatusTransfer();
			            	if(StringUtils.isNotBlank(status_transfer))
			            	{
			            		if(status_transfer.equals("10"))
			            		{
			            			businessVo.setStatusTransferName("已提交");
			            		}
			            		else if(status_transfer.equals("20"))
			            		{
			            			businessVo.setStatusTransferName("退回");
			            		}
			            		else if(status_transfer.equals("1"))
			            		{
			            			businessVo.setStatusTransferName("保存");
			            		}
			            	}
			            }
			            return true;
				}
            });
            
            for(int i=0;i<dhywDyVos.size();i++)
            {
            	String dealerId = dhywDyVos.get(i).getDealerId();
            	String sqlXmls = "select t.id,t.dealer_level from dp_base_dealer_info t where t.id = '"+dealerId+"' and t.dp_status = 1 limit 1";
            	List<Map<String, String>> mpaMaps = publicService.queryWhereSql(sqlXmls);
            	if(null != mpaMaps && mpaMaps.size() > 0)
            	{
            		String dealerLevelDisplay = cachedDictionaryService.getName(mpaMaps.get(0).get("dealer_level"), DataDicType.DEALER_LEVEL);
            		dhywDyVos.get(i).setDealerLevelDisplay(dealerLevelDisplay);
            	}
            }
            
            page.setRows(dhywDyVos);
        } 
        else 
        {
            page.setRows(CollectionInitUtil.emptyList());
        }
        maps.put("result", page);
        return maps;
	}
	
	/**
	* 新增一个模块，用于修改订单所属的业务员，详见系统设计文档
	*  @author  zhangpp
	*  @Title:  getYwYuanList  
	*    
	*  @param  @param paramsExt
	*  @param  @return
	*  @param  @throws Exception        设定文件  
	*  @return  Map<String,Object>        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@RequestMapping(value="getYwYuanList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getYwYuanList(@ApiIgnore ParamsExt paramsExt) throws Exception
	{
		Map<String, Object> maps = success();
		
		String whereSql = "";
		
		if(null != paramsExt && !("").equals(paramsExt))
		{
			String dayEnum = paramsExt.getDayEnum();
			
			if(null != dayEnum && !("").equals(dayEnum))
			{
				int stamp = ZhppDateUtil.dateConvertStamp();
				
				if(dayEnum.equals("1"))
				{
					whereSql += " and t.created >= "+stamp + " and t.created < "+(stamp + 86400);
				}
				else if(dayEnum.equals("2"))
				{
					whereSql += " and t.created < "+stamp + " and t.created >= "+(stamp - 86400 * 2);  
				}
				else if(dayEnum.equals("3"))
				{
					whereSql += " and t.created > (unix_timestamp() - 3600 * 24 * 7) ";
				}
			}
			
			String submitTimeStart = paramsExt.getSubmitTimeStart();
			String submitTimeEnd = paramsExt.getSubmitTimeEnd();
			
			if((null != submitTimeStart && !("").equalsIgnoreCase(submitTimeStart)) && (null != submitTimeEnd && !("").equals(submitTimeEnd)))
			{
				int start = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
				int end =  ZhppDateUtil.dateConvertTimeStamp(submitTimeEnd, "yyyy-MM-dd");
				whereSql += " and t.created >= "+start + " and t.created < "+ (end + 86400);
			}
			else
			{
				if(null != submitTimeStart && !("").equals(submitTimeStart))
				{
					int start = ZhppDateUtil.dateConvertTimeStamp(submitTimeStart, "yyyy-MM-dd");
					whereSql += " and t.created >= "+start;
				}
				else if(null != submitTimeEnd && !("").equals(submitTimeEnd))
				{
					int end =  ZhppDateUtil.dateConvertTimeStamp(submitTimeEnd, "yyyy-MM-dd");
					whereSql += " and t.created < "+(end + 86400);
				}
			}
			whereSql += " and t.busi_status < 30 ";
			
			AbstractSysUser currentUser = getCurrentUser();
			String userId = currentUser.getId();
			String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' ";
			List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
			if(null == mapList || 0 == mapList.size())
			{
				return maps;
			}
			
			if(mapList.size() > 0)
			{
				whereSql += " and ( ";
				
				Map<String, String> m = mapList.get(0);
				String code_unit = m.get("code_unit").toString();
				whereSql += " u.salersman_code like CONCAT('"+code_unit+"','%') ";
				
				for(int i=1;i<mapList.size();i++)
				{
					m = mapList.get(i);
					code_unit = m.get("code_unit").toString();
					whereSql += " or u.salersman_code like CONCAT('"+code_unit+"','%') ";
				}
				whereSql += " ) ";
			}
			
			paramsExt.setWhereSql(whereSql);
			paramsExt.notDeleted();
	        PageVo page = getPage(paramsExt);
	        int records = daiZhongYwService.countYwYuanList(paramsExt);
	        page.setRecords(records);
	        if (records > 0) 
	        {
	        	paramsExt.setOrderSql(" t.created desc ");
	        	List<BusinessVo> dhywDyVos = daiZhongYwService.getYwYuanList(paramsExt);
	        	redisObjectClient.execute(new RedisCallback<Boolean>() {

					@Override
					public Boolean doInRedis(RedisConnection redisConnection)
							throws DataAccessException {
						for(int i=0;i<dhywDyVos.size();i++)
						{
							BusinessVo businessVo = dhywDyVos.get(i);
							String channelType = businessVo.getChannelType();
			            	SimpleDataDictionary simpleDataDictionary1 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelType, DataDicType.CHANNEL_TYPE.getCode());
			            	businessVo.setChannelType(simpleDataDictionary1 == null ? "" : simpleDataDictionary1.getName());
			            	
			            	String channelStatus = businessVo.getChannelStatus();
			            	SimpleDataDictionary simpleDataDictionary2 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelStatus, DataDicType.CHANNEL_STATUS.getCode());
			            	businessVo.setChannelStatus(simpleDataDictionary2 == null ? "" : simpleDataDictionary2.getName());
			            	
			            	String bankLoan = businessVo.getBankLoan();
			            	SimpleDataDictionary simpleDataDictionary3 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), bankLoan, DataDicType.LOAN_BANK.getCode());
			            	businessVo.setBankLoan(simpleDataDictionary3 == null ? "" : simpleDataDictionary3.getName());
						}
						return true;
					}
				});
	            page.setRows(dhywDyVos);
	        } 
	        else 
	        {
	            page.setRows(CollectionInitUtil.emptyList());
	        }
	        maps.put("result", page);
		}
		return maps;
	}
	
	
	/**
	*  修改业务员
	*  @author  zhangpp
	*  @Title:  updateYw  
	*    
	*  @param  @param paramsExt
	*  @param  @return
	*  @param  @throws Exception        设定文件  
	*  @return  Map<String,Object>        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@RequestMapping(value="updateYw",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> updateYw(UpdateYwExt updateYwExt) throws Exception
	{
		Map<String, Object> maps = success();
		AbstractSysUser currentUser = getCurrentUser();
		daiZhongYwService.updateYw(currentUser, updateYwExt);
		return maps;
	}
}

